package com.gitee.wsl.ext.map

import kotlin.jvm.JvmName

typealias ListsMap<K, V> = Map<K, Collection<V>>
typealias MutableListsMap<K, V> = MutableMap<K, MutableList<V>>

fun <K, V> ListsMap<K, V>.contains(key: K, value: V): Boolean {
    return get(key)?.contains(value) == true
}

@Suppress("kotlin:S6524")
inline fun <K, V> MutableListsMap<K, V>.add(
    key: K,
    value: V,
    setGen: () -> MutableList<V> = ::mutableListOf
) {
    val list = getOrPut(key, setGen)
    list.add(value)
}

@Suppress("kotlin:S6524")
fun <K, V> MutableListsMap<K, V>.remove(key: K, value: V): Boolean {
    return get(key)?.remove(value) == true
}

typealias MutableSetsMap<K, V> = MutableMap<K, MutableSet<V>>

@Suppress("kotlin:S6524")
@JvmName("addUseGenSet")
 inline fun <K, V> MutableSetsMap<K, V>.add(
    key: K,
    value: V,
    setGen: () -> MutableSet<V> = ::mutableSetOf
) {
    val list = getOrPut(key, setGen)
    list.add(value)
}

@Suppress("kotlin:S6524")
@JvmName("removeSet")
fun <K, V> MutableSetsMap<K, V>.remove(key: K, value: V): Boolean {
    return get(key)?.remove(value) == true
}
